
package com.compuvest.web;

import java.util.ArrayList;

public class Items implements java.io.Serializable {

    public final static int SPECIAL =       0x1;    // 0000 0001
    public final static int CLOSEOUT =      0x1<<1; // 0000 0010
    public final static int COMMINGSOON =   0x1<<2; // 0000 0100 (Ships in 3-5 days)
    public final static int BESTPRICE =     0x1<<3; // 0000 1000

    public static final int LINE_ON_PAGE =  15;

    public final static String PRICEFORM = "<span class='rpr'>$%,.2f</span>";

    private final ArrayList<Item> contents;
    private final ArrayList<Category> categories;
    private String strCategories;
    private final ArrayList<Category> subcategories;
    private final ArrayList<Preference> prefs;
//    private ArrayList<Item> relativeItems;

    private int eventTime = 0;
    private int itemsCount = 0;

    private int categoryID;
    private int subcategoryID;
    private String categoryName;
    private String subcategoryName;
    private String relativeJSON;

    public Items() {
        contents = new ArrayList<>(LINE_ON_PAGE);
        categories = new ArrayList<>(50);
        strCategories = "";
        subcategories = new ArrayList<>(50);
        prefs = new ArrayList<>(7);
//        relativeItems = new ArrayList<Item>(10);
    }

    public int getEventTime()                       { return eventTime; }
    public void setEventTime(int eventTime)         { this.eventTime = eventTime; }

    public ArrayList<Item> getItems()               { return contents; }
    public void addItem(Item item)                  { contents.add(item); }

    public ArrayList<Preference> getPreference()    { return prefs; }
    public void addPreference(Preference pref)      { this.prefs.add(pref); }

    public String getRelativeItemJSON()             { return relativeJSON; }
    public void setRelativeItemJSON(String json)    { this.relativeJSON = json; }

    public int getItemsCount()                      { return itemsCount; }
    public void setItemsCount(int itemsCount)       { this.itemsCount = itemsCount; }

    public int getCategoryID()                          { return categoryID; }
    public void setCategoryID(int categoryID)           { this.categoryID = categoryID; }

    public int getSubcategoryID()                       { return subcategoryID; }
    public void setSubcategoryID(int categoryID)        { this.subcategoryID = categoryID; }

    public String getCategoryName()                     { return categoryName; }
    public void setCategoryName(String name)            { this.categoryName = name; }

    public String getSubcategoryName()                  { return subcategoryName; }
    public void setSubcategoryName(String name)         { this.subcategoryName = name; }

    public String getStrCategories()			{ return strCategories; }
    public void setStrCategories(String categories)	{ this.strCategories = categories; }

    public ArrayList<Category> getCategories()		{ return categories; }
    public void addCategory(Category category)		{ categories.add(category); }

    public ArrayList<Category> getSubcategories()	{ return subcategories; }
    public void addSubcategory(Category subcategory)    { subcategories.add(subcategory); }

    public int size()                               { return contents.size(); }
    public boolean isEmpty()                        { return contents.isEmpty(); }

    public int getPages() {
        return (itemsCount % LINE_ON_PAGE == 0) ? itemsCount / LINE_ON_PAGE : itemsCount / LINE_ON_PAGE + 1;
    }

    public String getPriceMessage(int mask) {
        if((mask & BESTPRICE) != 0)     return("Best Price");
        else if((mask & SPECIAL) != 0)	return("Special");
        else if((mask & CLOSEOUT) != 0) return("Clearance");
        else                            return("&nbsp;");
    }

// for Reseller
    public String getResellerPriceLine(final Item item) {

        if(item.getResPrice1() == 0d) return "";

        StringBuilder line = new StringBuilder(150);
        line.append("<div class='rsp'>&#x95; Your price: ");
        if(item.getResPrice1() != 0d) {
            line.append("1+ ").append(String.format(PRICEFORM, item.getResPrice1()));
        }
        if(item.getResQuantity2() != 0 && item.getResPrice2() != 0d) {
            line.append("&nbsp; | &nbsp;").append(item.getResQuantity2() + 1).append("+ ").append(String.format(PRICEFORM, item.getResPrice2()));
        }
        if(item.getResQuantity3() != 0 && item.getResPrice3() != 0d) {
             line.append("&nbsp; | &nbsp;").append(item.getResQuantity3() + 1).append("+ ").append(String.format(PRICEFORM, item.getResPrice3()));
        }
        line.append("</div>");

        return line.toString();
    }
}
